package com.ruoyi.project.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.Requirement;
import com.ruoyi.project.service.IRequirementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 需求Controller
 * 
 * @author ruoyi
 * @date 2025-04-06
 */
@RestController
@RequestMapping("/project/requirement")
public class RequirementController extends BaseController
{
    @Autowired
    private IRequirementService requirementService;

    /**
     * 查询需求列表
     */
    @PreAuthorize("@ss.hasPermi('project:requirement:list')")
    @GetMapping("/list")
    public TableDataInfo list(Requirement requirement)
    {
        startPage();
        List<Requirement> list = requirementService.selectRequirementList(requirement);
        return getDataTable(list);
    }

    /**
     * 导出需求列表
     */
    @PreAuthorize("@ss.hasPermi('project:requirement:export')")
    @Log(title = "需求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Requirement requirement)
    {
        List<Requirement> list = requirementService.selectRequirementList(requirement);
        ExcelUtil<Requirement> util = new ExcelUtil<Requirement>(Requirement.class);
        util.exportExcel(response, list, "需求数据");
    }

    /**
     * 获取需求详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:requirement:query')")
    @GetMapping(value = "/{reqId}")
    public AjaxResult getInfo(@PathVariable("reqId") Long reqId)
    {
        return success(requirementService.selectRequirementByReqId(reqId));
    }

    /**
     * 新增需求
     */
    @PreAuthorize("@ss.hasPermi('project:requirement:add')")
    @Log(title = "需求", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Requirement requirement)
    {
        return toAjax(requirementService.insertRequirement(requirement));
    }

    /**
     * 修改需求
     */
    @PreAuthorize("@ss.hasPermi('project:requirement:edit')")
    @Log(title = "需求", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Requirement requirement)
    {
        return toAjax(requirementService.updateRequirement(requirement));
    }

    /**
     * 删除需求
     */
    @PreAuthorize("@ss.hasPermi('project:requirement:remove')")
    @Log(title = "需求", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reqIds}")
    public AjaxResult remove(@PathVariable Long[] reqIds)
    {
        return toAjax(requirementService.deleteRequirementByReqIds(reqIds));
    }
}
